#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <conio.h>

#define RED SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
#define GREEN SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
#define BLUE SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
#define GREENB SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY);
#define REDB SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_INTENSITY);
#define BLUEB SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_INTENSITY);
#define YELLO SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
#define INDIG SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
#define MENU "Guess number"
#define STARS "**************************"

int compare(const char *player1,const char *player2);

int main(void)
{
    int times,Dice,enter,enter2,mod,test;
    char ch;                            /*ch记录玩家在更改姓名时的选择的变量*/
    char player1[50],player2[50];
    srand((unsigned int)time(NULL));
	INDIG printf("         %s%s\n\n",STARS,STARS);
    REDB printf("                   %s\n\n",MENU);
	GREENB printf("         %s%s\n\n",STARS,STARS);
    INDIG printf("你准备好了吗?\n(按Enter键继续......)\n");
    getchar();
    for(;;)
    {
        REDB printf("←_←请输入玩家1的名字:\n");
        GREENB scanf("%s",player1);
        YELLO printf("←_←请输入玩家2的名字:\n");
        GREENB scanf("%s",player2);

        test = compare(player1,player2);
        for(;;)
        {
            if(test)
            {
            YELLO printf("天呐噜!你们的名字难道一样吗╮(￣▽￣)╭?\n");
            BLUEB printf("那你们重新输入自己的名字吧!\n");
            GREENB printf("(;?_?)泥萌想要修改哪一个玩家的名字(x：玩家1；y：玩家2；z：全部)?\n");
            REDB printf("请键入X,Y,Z三个按键进行选择:\n");
            ch = getch();
            if(ch == 'X' || ch == 'x')
            {
                INDIG printf("现在有请玩家1修改名字:\n");
                scanf("%s",player1);
            }
            if(ch == 'Y' || ch == 'y')
            {
                GREENB printf("现在有请玩家2修改名字:\n");
                scanf("%s",player2);
            }
            if(ch == 'Z' || ch == 'z')
            {
                INDIG printf("现在首先有请玩家1修改名字:\n");
                scanf("%s",player1);
                GREENB printf("然后，有请玩家2修改名字:\n");
                scanf("%s",player2);
                REDB printf("(′?ω?`)");
            }
            test = compare(player1,player2);
            }
            if(test)
            {
                REDB printf("看来你是成心的!\n");
                break;
            }
            else
            {
            break;
            }

        }

        BLUEB printf("≧０≦现在请输入骰子的数值上限:\n");
        REDB scanf("%d",&mod);

        Dice = rand() % mod + 1;

        BLUEB printf("请玩家1进行输入:\n");
        scanf("%d",&enter);
        for(;;)
        {
            if(enter > Dice)
            {
                GREENB printf("(┙>∧<)┙へ┻┻%d太大了，请玩家2进行输入:\n",enter);
                scanf("%d",&enter2);
            }
            if(enter2 > Dice)
            {
                BLUEB printf("(┙>∧<)┙へ┻┻%d太大了，请玩家1进行输入:\n",enter2);
                scanf("%d",&enter);
            }
            if(enter < Dice)
            {
                GREENB printf("(┙>∧<)┙へ┻┻%d太小了，请玩家2进行输入:\n",enter);
                scanf("%d",&enter2);
            }
            if(enter2 < Dice)
            {
                BLUEB printf("(┙>∧<)┙へ┻┻%d太小了，请玩家1进行输入:\n",enter2);
                scanf("%d",&enter);
            }
            if(enter == Dice)
            {
                REDB printf("o(*≧▽≦)ツ没错，%s你猜对了!\n",player1);
                break;
            }
            if(enter2 == Dice)
            {
                REDB printf("o(*≧▽≦)ツ没错，%s你猜对了!\n",player2);
                break;
            }

        }
        INDIG printf("你想要去再玩一遍吗?Y/N\n");
        for(;;)
        {
            if((ch = getchar()) == 'N' || (ch = getchar()) == 'n')
            {
                break;
            }
            if(ch != 'Y' || ch != 'y')
            {
                REDB printf("请输入正确的字母选项!\n");
            }
        }

        break;

    }

    system("pause");
    return 0;
}

int compare(const char *player1,const char *player2)
{
    int temp = 0;
    int times = 0;
    while(temp < 50)
    {
        if(*(player1 + temp) == *(player2 + temp))
        {
            times++;
        }
        temp++;
    }
    if(times >= 50)
    {
        return (1);
    }
    else
    {
        return (0);
    }
}

